package com.controller;

import com.pojo.TbSupplier;
import com.pojo.TbWorker;
import com.service.WorkerService;
import com.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/worker")
public class WorkerController {
    @Autowired
    JSONResult jsonResult;
    @Autowired
    WorkerService workerService;

    @GetMapping("/findAllWorkerByWorkerName")
    public JSONResult findAllWorkerByWorkerName(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam(value = "workerName",defaultValue = "") String workerName){
        return workerService.findAllWorkerByWorkerName(page,limit,workerName);
    }
    @GetMapping("/findAllWorker")
    public JSONResult findAllWorker(@RequestParam("page") int page,@RequestParam("limit") int limit){
        return workerService.findAllWorker(page,limit);
    }


    @GetMapping("/findAllWorkerByState")
    public JSONResult findAllWorkerByState(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam(value = "state",defaultValue = "-1") int state){
        return workerService.findAllWorkerByState(page,limit,state);
    }


    @PostMapping("/addWorker")
    public JSONResult addWorker(@RequestBody TbWorker worker){
        return workerService.addWorker(worker);
    }


    @GetMapping("/deleteWorker")
    public JSONResult deleteWorker(@RequestParam("workerId") int workerId){
        return workerService.deleteWorker(workerId);
    }


    @PostMapping("/updateWorker")
    public JSONResult updateWorker(@RequestBody TbWorker worker){
        return workerService.updateWorker(worker);
    }


    @GetMapping("/findWorkerById")
    public JSONResult findWorkerById(@RequestParam("workerId") int workerId){
        return workerService.findWorkerById(workerId);
    }
}
